-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix billboard on terrain and Globe.getHeight #4622
Conversation
better handling of under ellipsoid surface terrain
b2dc7c6
to
9f7d911
Compare
I had a typo in the commit message ( |
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(cartesian, ray.direction); | ||
|
||
// compute origin point, to account for a case where the terrain is under ellipsoid surface | ||
var minimumHeight = Math.min(defaultValue(tile.data.minimumHeight, 0.0), 0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use -11500.0
. For the lowest resolution terrain tiles, triangle vertices may be near the ellipsoid surface, but the interiors cutting through the ellipsoid will drop to around this height. Is there a reason you didn't use Cartesian3.ZERO
? Did you run into precision issues in the triangle intersection test?
This looks good to me. Just that one comment. |
Also, please update CHANGES.md. |
Thanks @bagnell!
A ray from Anyway, I discussed this problem with Omer Bar from Survey Of Israel/Geodesy department and he suggested to use the intersection point of the Theoretically, the intersection point can be outside the ellipsoid, though I really tried but didn't get such result. If you want to see how this intersection point behaves, see this sandcastle example that shows how this point is changed relative to the normal. Do you see any problem with this approach? BTW, |
a256f7f
to
74a7de5
Compare
I changed the code a bit according to @pjcozzi 's suggestion in #4682. @bagnell, I didn't find any other usage of This is ready for review. |
Cartesian3.subtract(cartesian, vectorToMinimumPoint, ray.origin); | ||
|
||
// Theoretically, the intersection point can be outside the ellipsoid, so we have to check if the result's 'z' is inside the ellipsoid (with some buffer) | ||
if (Math.abs(ray.origin.z) >= ellipsoid.radii.z -11500.0){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hard coding -11500.0
here and below, can this use some percentage of ellipsoid.radii.maximumComponent? Or does the buffer need to be this big? Instead, can it be a much smaller epsilon?
} | ||
|
||
if (mode === SceneMode.SCENE3D) { | ||
Cartesian3.clone(Cartesian3.ZERO, scratchRay.origin); | ||
Cartesian3.normalize(data.position, scratchRay.direction); | ||
var surfaceNormal = ellipsoid.geodeticSurfaceNormal(data.positionOnEllipsoidSurface, scratchRay.direction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this duplicate code belong in a utility function for Ray
or Ellipsoid
? That would also be more testable so we could add unit tests.
Ah, of course. I can't see anything wrong with your new approach. This looks good to me. @pjcozzi can merge when this is ready. |
change Globe.js and QuadtreePrimitive.js to work with Ellipsoid.getSurfaceNormalIntersectionWithZAxis add tests
Hi,
This value was taken from cesium code, here. @bagnell wrote about this value:
For this value to be be calculated accurately we need: To make it possible we have to do some code refactoring, and I think that this is out of the scope of this PR.
Anyway, for Earth datums all of this is not needed since the intersection point with the After I tested it practically, I asked a mathematician colleague to prove that formally and I put here the proof for that (I had to upload it as a pictures because MD doesn't support latex). For Earth (WGS84 ellipsoid), the absolute value of this constant is 0.00673 (i.e. point is always very close to Cartesian3.ZERO); For Moon, according to wikipedia values, the constant is 0.0024. I don't really know other shapes of planetary bodies that cesium might represent in the future, hence there is the fallback we discussed above.
I added This is ready. |
Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function(position, buffer, result) { | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
if (!defined(position)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor, but could you please add unit tests for these three DeveloperError
cases?
Thanks for the updates, @duvifn! I made some trivial style tweaks for consistency with the rest of the Cesium codebase. Let me know when you add those other unit tests (it will be easy) and we'll merge this. If we merge it early next week, it will ship in Cesium 1.29 on January 2. |
Hi @pjcozzi ! Did you mean these specs? (already there), |
Ah yes, great! Thanks again for this contribution! |
fix #4598 and #3411